package com.briup.jdbc;

import com.alibaba.druid.pool.DruidDataSourceFactory;
import org.junit.Test;

import javax.sql.DataSource;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.util.Properties;

public class DruidTest {
    @Test
    public void testProperties() {
        Properties properties = new Properties();
        InputStream in = DruidTest.class.getClassLoader().getResourceAsStream("com/briup/jdbc/druid.properties");
        try {
            properties.load(in);
            properties.forEach((k,v)->{
                System.out.println(k+" = "+v);
            });

        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    @Test
    public void testDruid() throws Exception {
        // 1、准备配置文件读取
        Properties properties = new Properties();
        InputStream in = DruidTest.class.getClassLoader().getResourceAsStream("com/briup/jdbc/druid.properties");
        properties.load(in);
        // 2、创建连接对象
        DataSource dataSource = DruidDataSourceFactory.createDataSource(properties);
        for (int i = 0; i < 100; i++) {
            Connection connection = dataSource.getConnection();
            System.out.println(connection);
            System.out.println(connection.getClass());
        }
    }
}
